//
//  HJDConsultController.m
//  JYHospital
//
//  Created by 胡金东 on 16/3/31.
//  Copyright © 2016年 胡金东. All rights reserved.
//

#import "HJDHomeController.h"

#import "HJDHealthViewController.h"
#import "HJDSetViewController.h"
#import "HJDSetDateViewController.h"
#import "HJDCalculateDateViewController.h"
#import "HJDEVersionViewController.h"
#import "HJDViewController.h"

#import "HJDMondayTableViewController.h"
#import "HJDLabel.h"
#import "HJDTuesdayTableViewController.h"
#import "HJDWednesdayTableViewController.h"
#import "HJDThursdayTableViewController.h"
#import "HJDFridayTableViewController.h"
#import "HJDSaturdayTableViewController.h"
#import "HJDSundayTableViewController.h"

#import "HJDBannerOneViewController.h"
#import "HJDBannerTwoViewController.h"
#import "HJDBannerThreeViewController.h"
#import "HJDBannerFourViewController.h"
#import "HJDBannerFiveViewController.h"

#import "HJDCTimeViewController.h"
#import "HJDDetailTimeTableViewController.h"

//孕期管理
#import "HJDPofileControllerr.h"
//一键挂号
#import "HJDRegistrationViewController.h"
//孕期档案
#import "HJDGestationViewController.h"

#import "HJDLoginViewController.h"

#import "AFNetworking.h"
#import "MBProgressHUD.h"
#import "RESideMenu.h"
#import "HJDTabBarController.h"
//#import "HJDPesonalCenterViewController.h"
#import "HJDNavigationController.h"

#import "BSMacros.h"


#define IMAGECOUNT 5
#define margin 5
#define imageUrl @"http://192.168.1.169:8080"

@interface HJDHomeController ()<UIScrollViewDelegate>
{
    NSInteger m;
}



//图片轮转
@property (nonatomic,strong)UIScrollView *scrollView;

@property (nonatomic,strong)UIPageControl *pageControl;
@property (nonatomic,strong)NSTimer *timer;
//整体页面
@property (nonatomic,strong)UIScrollView *scroll;
//准备按钮
@property (nonatomic,strong) UIButton *papreBtn;
//第四个按钮
@property (nonatomic,strong) UILabel *fourLbl;

@property (nonatomic,strong)  UIView *viewLbl;


@property (nonatomic,strong) UIScrollView * upScrollView;

@property (nonatomic,strong) UIScrollView * downScrollView;

@property (nonatomic,strong)UIScrollView *downscroll;

@property (nonatomic,assign) NSInteger * id;
@property (nonatomic,strong) NSURL * imageurl;

//最上的天数
@property (nonatomic,strong) UILabel *timeLbl ;



//背景
@property (nonatomic,strong) UIView * backgroundView;

@property (nonatomic,strong) UIView *viewM;




@end

@implementation HJDHomeController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //隐藏导航栏
    self.navigationController.navigationBarHidden = YES;
    
                NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
                NSDateComponents *comp = [[NSDateComponents alloc]init];
                NSInteger flags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday |
                NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
                NSDate *nowDate = [NSDate date];
    
                comp = [calendar components:flags fromDate:nowDate];
            long int week = [comp weekday];
    if (week == 1) {
        week = 8;
    }else if (week == 2){
        CGPoint offset1 = self.downScrollView.contentOffset;
        offset1.x = self.downScrollView.frame.size.width;
        [self.downScrollView setContentOffset:offset1 animated:YES];

    }
 NSInteger shi = week -2;

    CGPoint offset1 = self.downScrollView.contentOffset;
    offset1.x = shi * self.downScrollView.frame.size.width;
    [self.downScrollView setContentOffset:offset1 animated:YES];
  
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor getColorWithHexNumber:@"F1F1EE"];
    
    [self setUpNavi];
    
  
    
    [self setupScrollView];
    [self setupPageControl];
    
    [self setUpupScrollView];
    
    [self setUpdownScrollView];
    //添加内容
    [self setUpContent];
    //    添加标题
    [self setUpTitle];
    //    默认显示第0个子控制器 从0开始
//    [self scrollViewDidEndScrollingAnimation:self.downScrollView];
    
    


    m = 0;

    }
-(void)setUpNavi
{
    
    self.scroll = [[UIScrollView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.scroll.delegate = self;
//    self.scroll.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"首页背景"]];
    
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.scroll.showsVerticalScrollIndicator = YES;//垂直移动
    self.scroll.showsHorizontalScrollIndicator = NO;//水平移动
    //上下滑动
    self.scroll.contentSize = CGSizeMake(HJDWidth,900 ) ;
    
    
    [self.view addSubview: self.scroll];
    //    背景
    self.backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,750/2 ,1092/2 )];
    self.backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"首页背景"]];
    [self.scroll addSubview:self.backgroundView];
    
    
    
    CGFloat leftX = HJDHorizontalMargin;
    CGFloat leftY = HJDVerticalMargin;
    CGFloat leftW = 34;
    CGFloat leftH = 34;
    UIButton *navleftBtn = [[UIButton alloc]initWithFrame:CGRectMake(leftX, leftY, leftW, leftH)];
    [navleftBtn setBackgroundImage:[UIImage imageNamed:@"矢量智能对象侧"] forState:UIControlStateNormal];
    [navleftBtn addTarget:self action:@selector(MyCenterClick) forControlEvents:UIControlEventTouchUpInside];

    [self.backgroundView addSubview:navleftBtn];
    
    
    
    CGFloat rightX = HJDWidth -35-HJDHorizontalMargin;
    CGFloat rightY = leftY;
    CGFloat rightW = 34;
    CGFloat rightH = 34;
    UIButton *navrightBtn = [[UIButton alloc]initWithFrame:CGRectMake(rightX, rightY, rightW, rightH)];
    [navrightBtn addTarget:self action:@selector(push) forControlEvents:UIControlEventTouchUpInside];
    [navrightBtn setBackgroundImage:[UIImage imageNamed:@"矢量智能对象@2x_28"] forState:UIControlStateNormal];
    [navrightBtn setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateHighlighted];
//    [navrightBtn setBackgroundColor:[UIColor getColorWithHexNumber:@"CFCFCF"]];
    [self.backgroundView addSubview:navrightBtn];
    
    CGFloat X = HJDWidth/2- 120/2;
    CGFloat Y = 20;
    CGFloat W = 120;
    CGFloat H = 34;
    UIView *viewTimeSele = [[UIView alloc]initWithFrame:CGRectMake(X, Y, W, H)];
    viewTimeSele.backgroundColor = [UIColor getColorWithHexNumber:@"323232"];
    viewTimeSele.alpha = 0.2;
    [viewTimeSele setRadius:18 borderWith:0 borderColor:nil];
    [self.scroll addSubview:viewTimeSele];
    
   self.timeLbl = [[UILabel alloc]init];
    self.timeLbl.text = @"388";
    
    self.timeLbl.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
    self.timeLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:19];
   
    CGSize  timeLblSize = [_timeLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.timeLbl.font,NSFontAttributeName ,nil]];
    self.timeLbl.textAlignment = NSTextAlignmentCenter;
    CGFloat timeLblX = (HJDWidth - timeLblSize.width)/2;
    CGFloat timeLblY = 20;
    self.timeLbl.frame = (CGRect){{timeLblX -10,timeLblY +5},timeLblSize};
    self.timeLbl.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
    [self.backgroundView addSubview:self.timeLbl];
    
    UILabel *upLbll = [[UILabel alloc]init];
    upLbll.text = @"天";
    upLbll.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
    upLbll.font = [UIFont fontWithName:@"HelveticaNeue" size:19];
    CGSize LbllSize = [upLbll.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:upLbll.font,NSFontAttributeName, nil]];
    CGFloat LbllX = CGRectGetMaxX(self.timeLbl.frame);
    CGFloat LbllY = timeLblY + 5;
    upLbll.frame = (CGRect){{LbllX,LbllY},LbllSize};
    
    
    upLbll.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
    [self.backgroundView addSubview:upLbll];

    
    
    
    
    
    CGFloat leftBtnW = 9;
    CGFloat leftBtnH = 35/2;
    CGFloat leftBtnX = X + 9;
    CGFloat leftBtnY = 28;
    
    UIButton *leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(leftBtnX, leftBtnY, leftBtnW, leftBtnH)];
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"首页上"] forState:UIControlStateNormal];

//    leftBtn.backgroundColor = [UIColor getColorWithHexNumber:@"CFCFCF"];
    [leftBtn addTarget:self action:@selector(upDayClick) forControlEvents:UIControlEventTouchUpInside];
    [self.backgroundView addSubview:leftBtn];
    
    CGFloat rightBtnW = 9;
    CGFloat rightBtnH = 35/2;
    CGFloat rightBtnX = CGRectGetMaxX(viewTimeSele.frame) - 18;
    CGFloat rightBtnY = 28;
    
    UIButton *rightBtn = [[UIButton alloc]initWithFrame:CGRectMake(rightBtnX, rightBtnY, rightBtnW, rightBtnH)];
    [rightBtn setBackgroundImage:[UIImage imageNamed:@"︿@2x_0"] forState:UIControlStateNormal];
//    rightBtn.backgroundColor = [UIColor getColorWithHexNumber:@"CFCFCF"];
    [rightBtn addTarget:self action:@selector(nextDayClick) forControlEvents:UIControlEventTouchUpInside];
    [self.backgroundView addSubview:rightBtn];
    
    //   出生天数
    CGFloat viewW = 198 /2 + 10;
    CGFloat viewH = 95/2;
    CGFloat viewX = (HJDWidth - viewW)/2;
    CGFloat viewY = CGRectGetMaxY(viewTimeSele.frame) + HJDVerticalMargin;
   self.viewLbl = [[UIView alloc]init];
       self.viewLbl.frame = CGRectMake(viewX, viewY, viewW, viewH);
    [   self.viewLbl setRadius:50/2 -2 borderWith:0 borderColor:[UIColor whiteColor]];
       self.viewLbl.backgroundColor = [UIColor getColorWithHexNumber:@"5CC6AB"];
    [self.backgroundView addSubview: self.viewLbl];
    
    UILabel *babyLbl = [[UILabel alloc]init];
    babyLbl.text = @"宝宝出生";
    babyLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:15];
    CGSize  babyLblSize = [babyLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:babyLbl.font,NSFontAttributeName ,nil]];
    CGFloat babyLblX = (viewW - babyLblSize.width)/2;
    CGFloat babyLblY = 2;
    babyLbl.frame = (CGRect){{babyLblX,babyLblY},babyLblSize};
    babyLbl.textAlignment = NSTextAlignmentCenter;
    babyLbl.textColor = [UIColor whiteColor];
    [self.viewLbl addSubview:babyLbl];
    
    UILabel *babyDayLbl = [[UILabel alloc]init];
    babyDayLbl.text = @"468";
    babyDayLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:24];
    CGSize  babyDayLblSize = [babyDayLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:babyDayLbl.font,NSFontAttributeName ,nil]];
    CGFloat babyDayLblX = (viewW - babyDayLblSize.width)/2;
    CGFloat babyDayLblY = CGRectGetMaxY(babyLbl.frame) -2 ;
    babyDayLbl.frame = (CGRect){{babyDayLblX,babyDayLblY},babyDayLblSize};
    babyDayLbl.textAlignment = NSTextAlignmentCenter;
    babyDayLbl.textColor = [UIColor whiteColor];
    [self.viewLbl addSubview:babyDayLbl];
    
    
    CGFloat TLblX = CGRectGetMaxX(babyDayLbl.frame);
    CGFloat TLblY = babyDayLblY ;
    CGFloat TLblW = 20;
    CGFloat TLblH = 15;
    UILabel *TLbl = [[UILabel alloc]initWithFrame:CGRectMake(TLblX, TLblY +9, TLblW, TLblH)];
    TLbl.text = @"天";
    TLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:13];
    
        TLbl.textColor = [UIColor getColorWithHexNumber:@"FE93A2"];
    [self.viewLbl addSubview:TLbl];
    

    
}

//个人中心
-(void)MyCenterClick
{
    [self.sideMenuViewController presentLeftMenuViewController];
}
//星期
-(void)setUpupScrollView
{
    CGFloat Y = CGRectGetMaxY(self.viewLbl.frame) ;
    self.upScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(45,Y , HJDWidth-45-30, 40)];
    self.upScrollView.backgroundColor = [UIColor clearColor];
    
    //       self.upScrollView.showsHorizontalScrollIndicator = YES;
    //    self.upScrollView.showsVerticalScrollIndicator = YES;
    self.upScrollView.delegate = self;
    [self.scroll addSubview:self.upScrollView];
    
    CGFloat imageX = HJDHorizontalMargin;
    CGFloat imageY = CGRectGetMaxY(self.viewLbl.frame);
    CGFloat imageW = 39/2;
    CGFloat imageH = 109/2;
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(imageX, imageY, imageW, imageH)];
    imageView.image =[UIImage imageNamed:@"别针"];
    [self.backgroundView addSubview:imageView];
    
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSDateComponents *comp = [[NSDateComponents alloc]init];
    NSInteger flags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday |
    NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    NSDate *nowDate = [NSDate date];
    comp = [calendar components:flags fromDate:nowDate];
    NSInteger month = [comp month];
    NSInteger day = [comp day];

    
        UILabel *dateLbl = [[UILabel alloc]init];
        dateLbl.text = [NSString stringWithFormat:@"%ld.",(long)month];
        dateLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:25];
        CGSize  dateLblSize = [dateLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:dateLbl.font,NSFontAttributeName ,nil]];
        CGFloat dateLblX = HJDWidth - 80;
        CGFloat dateLblY = CGRectGetMaxY(self.upScrollView.frame) -8;
        dateLbl.frame = (CGRect){{dateLblX,dateLblY},dateLblSize};
        dateLbl.textAlignment = NSTextAlignmentCenter;
        dateLbl.textColor = [UIColor getColorWithHexNumber:@"CFCFCF"];
        [self.scroll addSubview:dateLbl];
    
    
    
        UILabel *dayLbl = [[UILabel alloc]init];
        dayLbl.text = [NSString stringWithFormat:@"%ld",(long)day];
        dayLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:15];
        CGSize  dayLblSize = [dayLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:dayLbl.font,NSFontAttributeName ,nil]];
        CGFloat dayLblX = CGRectGetMaxX(dateLbl.frame);
        CGFloat dayLblY = dateLblY + 9;
        dayLbl.frame = (CGRect){{dayLblX,dayLblY},dayLblSize};
        dayLbl.textAlignment = NSTextAlignmentCenter;
        dayLbl.textColor = [UIColor getColorWithHexNumber:@"CFCFCF"];
        [self.backgroundView addSubview:dayLbl];
    
    
}


-(void)setUpdownScrollView
{
      CGFloat Y = CGRectGetMaxY(self.upScrollView.frame)+20 ;
    

    
    self.downScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(10, Y, HJDWidth -20, 180)];
     self.downScrollView.delegate = self;
    self.downScrollView.pagingEnabled = YES;
   
    //    水平滚动条不显示
    self.downScrollView.showsHorizontalScrollIndicator = NO;
    self.downScrollView.showsVerticalScrollIndicator = YES;

////    不让垂直拖动
//    self.downScrollView.alwaysBounceVertical = YES;

//不让水平拖动
    self.downScrollView.alwaysBounceHorizontal = NO;
//    self.downScrollView.bounces = NO;//NO时滚动不会超出可见范围
//    self.downScrollView.contentSize = CGSizeMake(HJDWidth - 20,400 );
    
    [self.backgroundView addSubview:self.downScrollView];
   
    
    self.viewM = [[UIView alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(self.downScrollView.frame), HJDWidth - 20, 230)];
    self.viewM.backgroundColor = [UIColor whiteColor];
    [self.backgroundView addSubview:self.viewM];

    
    CGFloat papreBtnX = HJDHorizontalMargin/2 ;
    CGFloat papreBtnY =  20;
    CGFloat papreBtnW = HJDWidth - HJDHorizontalMargin * 2 ;
    CGFloat papreBtnH = 39;
    self.papreBtn = [[UIButton alloc]initWithFrame:CGRectMake(papreBtnX, papreBtnY, papreBtnW, papreBtnH)];
    [self.papreBtn setBackgroundImage:[UIImage imageNamed:@"本周产检准备事项-----------------------前往)))"] forState:UIControlStateNormal];
//    self.papreBtn.backgroundColor = [UIColor getColorWithHexNumber:@"FE93A2"];
    [self.papreBtn addTarget:self action:@selector(papreBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.viewM addSubview:self.papreBtn];
    
        CGFloat viewMagrinX = 0;
        CGFloat viewMagrinY = CGRectGetMaxY(self.papreBtn.frame) +25 ;
    
        CGFloat viewMagrinW = HJDWidth;
        CGFloat viewMagrinH = 20;
        UIView *viewMarin = [[UIView alloc]initWithFrame:CGRectMake(viewMagrinX, viewMagrinY, viewMagrinW, viewMagrinH)];
    
        viewMarin.backgroundColor = [UIColor getColorWithHexNumber:@"F1F1EE"];
        [self.viewM addSubview:viewMarin];
    
    
        CGFloat btnMagrin = 29;
        CGFloat btnWith = (HJDWidth-  46 - btnMagrin *3)/4;
        CGFloat btnOneX = 23;
        CGFloat btnOneY = CGRectGetMaxY(viewMarin.frame) + 20;
        CGFloat btnOneW = btnWith;
        CGFloat btnOneH = btnWith;
        UIButton *btnOne = [[UIButton alloc]initWithFrame:CGRectMake(btnOneX, btnOneY, btnOneW, btnOneH)];
    //    [btnOne setBackgroundColor:[UIColor getColorWithHexNumber:@"FE93A2"]];
        [btnOne setBackgroundImage:[UIImage imageNamed:@"-0"] forState:UIControlStateNormal];
        [btnOne setRadius:btnOneW/2 borderWith:0 borderColor:nil];
    
        [btnOne addTarget:self action:@selector(oneClick) forControlEvents:UIControlEventTouchUpInside];
        [self.viewM addSubview:btnOne];
    
    
        UILabel *oneLbl = [[UILabel alloc]init];
        oneLbl.text = @"孕妈问诊";
        oneLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
        CGSize  oneLblSize = [oneLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:oneLbl.font,NSFontAttributeName ,nil]];
        CGFloat oneLblX = btnOneX + btnWith/2 - oneLblSize.width/2;
        CGFloat oneLblY = CGRectGetMaxY(btnOne.frame) + margin;
        oneLbl.frame = (CGRect){{oneLblX,oneLblY},oneLblSize};
        /**
         *   设置label的背景图片
         */
    //    UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"-0"]];
    //    [oneLbl setBackgroundColor:color];
        //    oneLbl.textAlignment = NSTextAlignmentCenter;
        oneLbl.textColor = [UIColor getColorWithHexNumber:@"848484"];
        [self.viewM addSubview:oneLbl];
    
    
        CGFloat btnTwoX = 23 + btnOneW +btnMagrin;
        CGFloat btnTwoY = btnOneY;
        CGFloat btnTwoW = btnWith;
        CGFloat btnTwoH = btnWith;
        UIButton *btnTwo = [[UIButton alloc]initWithFrame:CGRectMake(btnTwoX, btnTwoY, btnTwoW, btnTwoH)];
        [btnTwo setBackgroundColor:[UIColor getColorWithHexNumber:@"FE93A2"]];
        [btnTwo addTarget:self action:@selector(twoClick) forControlEvents:UIControlEventTouchUpInside];
        [btnTwo setRadius:btnOneW/2 borderWith:0 borderColor:[UIColor getColorWithHexNumber:@"FE93A2"]];
        [btnTwo setBackgroundImage:[UIImage imageNamed:@"矢量智能对象@2x_1"] forState:UIControlStateNormal];
        [self.viewM addSubview:btnTwo];
    
    
        UILabel *twoLbl = [[UILabel alloc]init];
        twoLbl.text = @"一键挂号";
        twoLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
        CGSize  twoLblSize = [twoLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:twoLbl.font,NSFontAttributeName ,nil]];
        CGFloat twoLblX = btnTwoX + btnWith/2 - twoLblSize.width/2;
        CGFloat twoLblY = CGRectGetMaxY(btnTwo.frame) +margin ;
        twoLbl.frame = (CGRect){{twoLblX,twoLblY},twoLblSize};
        //    oneLbl.textAlignment = NSTextAlignmentCenter;
        twoLbl.textColor = [UIColor getColorWithHexNumber:@"848484"];
        [self.viewM addSubview:twoLbl];
    
        CGFloat btnThreeX = 23 + (btnOneW +btnMagrin)*2;
        CGFloat btnThreeY = btnTwoY;
        CGFloat btnThreeW = btnWith;
        CGFloat btnThreeH = btnWith;
        UIButton *btnThree = [[UIButton alloc]initWithFrame:CGRectMake(btnThreeX, btnThreeY, btnThreeW, btnThreeH)];
        [btnThree setBackgroundColor:[UIColor getColorWithHexNumber:@"FE93A2"]];
        [btnThree addTarget:self action:@selector(threeClick) forControlEvents:UIControlEventTouchUpInside];
        [btnThree setRadius:btnOneW/2 borderWith:0 borderColor:[UIColor getColorWithHexNumber:@"FE93A2"]];
        [btnThree setBackgroundImage:[UIImage imageNamed:@"矢量智能对象@2x_40"] forState:UIControlStateNormal];
    
        [self.viewM addSubview:btnThree];
    
    
        UILabel *threeLbl = [[UILabel alloc]init];
        threeLbl.text = @"孕期档案";
        threeLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
        CGSize  threeLblSize = [threeLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:threeLbl.font,NSFontAttributeName ,nil]];
        CGFloat threeLblX = btnThreeX +btnWith/2 - threeLblSize.width/2;
        CGFloat threeLblY = CGRectGetMaxY(btnTwo.frame) +margin ;
        threeLbl.frame = (CGRect){{threeLblX,threeLblY},threeLblSize};
        //    oneLbl.textAlignment = NSTextAlignmentCenter;
        threeLbl.textColor = [UIColor getColorWithHexNumber:@"848484"];
        [self.viewM addSubview:threeLbl];
    
        CGFloat btnFourX = 23 + (btnOneW +btnMagrin)*3;
        CGFloat btnFourY = btnThreeY;
        CGFloat btnFourW = btnWith;
        CGFloat btnFourH = btnWith;
        UIButton *btnFour = [[UIButton alloc]initWithFrame:CGRectMake(btnFourX, btnFourY, btnFourW, btnFourH)];
        [btnFour setBackgroundColor:[UIColor getColorWithHexNumber:@"FE93A2"]];
        [btnFour addTarget:self action:@selector(fourClick) forControlEvents:UIControlEventTouchUpInside];
        [btnFour setRadius:btnOneW/2 borderWith:0 borderColor:[UIColor getColorWithHexNumber:@"FE93A2"]];
        [btnFour setBackgroundImage:[UIImage imageNamed:@"矢量智能对象@2x_96"] forState:UIControlStateNormal];
    
        [self.viewM addSubview:btnFour];
    
    
        self.fourLbl = [[UILabel alloc]init];
        self.fourLbl.text = @"孕期管理";
        self.fourLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
        CGSize  fourLblSize = [ self.fourLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys: self.fourLbl.font,NSFontAttributeName ,nil]];
        CGFloat fourLblX = btnFourX + btnWith/2 -fourLblSize.width/2;
        CGFloat fourLblY = CGRectGetMaxY(btnFour.frame) +margin ;
        self.fourLbl.frame = (CGRect){{fourLblX,fourLblY},fourLblSize};
        //    oneLbl.textAlignment = NSTextAlignmentCenter;
        self.fourLbl.textColor = [UIColor getColorWithHexNumber:@"848484"];
        [self.viewM addSubview: self.fourLbl];
    
    CGFloat viewMX = -10;
    CGFloat viewMY = CGRectGetMaxY(self.fourLbl.frame) + 25 ;
    CGFloat viewMW = HJDWidth ;
    CGFloat viewMH = 20;
    UIView *viewM = [[UIView alloc]initWithFrame:CGRectMake(viewMX, viewMY, viewMW, viewMH)];
    
    viewM.backgroundColor = [UIColor getColorWithHexNumber:@"F1F1EE"];
    [self.viewM addSubview:viewM];
    

    
}

//图片轮播
-(void)setupScrollView
{
    
    
    CGFloat scrollViewX = 0;
    CGFloat scrollViewY = 610;
    CGFloat scrollViewW = HJDWidth;
    CGFloat scrollViewH = 250/2;
    
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(scrollViewX, scrollViewY,scrollViewW,scrollViewH)];
    self.scrollView.delegate = self;
    
    NSString *url = @"/app/getBanner.do";
    NSString *path = [Hurl stringByAppendingString:url];
    AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    
    [mgr POST:path parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//        NSLog(@"yes --------%@",responseObject);
        NSDictionary *infoDic = (NSDictionary *)responseObject;

    
        
        for (int i = 0; i<2; i++) {
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(i * self.view.frame.size.width, 0,scrollViewW, scrollViewH)];
            NSString *info = infoDic[@"resultMap"][i][@"imageurl"];
//            NSLog(@"infojinf------%@",info);
            NSString *urlstring  = [NSString stringWithFormat:@"%@/%@",imageUrl,info];
             HJDLog(@"%@",urlstring);
            imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlstring ]]];
//                    imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",i+1]];
            imageView.userInteractionEnabled = YES; // UIImageView默认不允许用户交互
            UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClickImage)];
            [imageView addGestureRecognizer:singleTap];
            [self.scrollView addSubview:imageView];
        }

        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"error%@",error);
    }];

    
    
    
   
    self.scrollView.contentSize = CGSizeMake(IMAGECOUNT * self.view.frame.size.width, scrollViewH) ;
    self.automaticallyAdjustsScrollViewInsets = NO; //ScrollView不能在viewController划到顶
    self.scrollView.pagingEnabled = YES;//分页设置
    self.scrollView.showsVerticalScrollIndicator = NO;//垂直移动
    self.scrollView.showsHorizontalScrollIndicator = NO;//水平移动
    self.scrollView.bounces = NO;//NO时滚动不会超出可见范围
    [self.scroll addSubview:self.scrollView];
    [self addTimer];
}


-(void)addTimer
{
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(nextImage) userInfo:nil repeats:YES];
    self.timer = timer;
    //循环
    NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
    [runLoop addTimer:timer forMode:NSRunLoopCommonModes];
    
}

-(void)nextImage
{
    NSInteger page = self.pageControl.currentPage;
    if (page == self.pageControl.numberOfPages-1) {
        page = 0;
    }else{
        page ++;
    }
    CGFloat offsetX = page * self.scrollView.frame.size.width;
    [UIView animateWithDuration:1.0 animations:^{
        self.scrollView.contentOffset = CGPointMake(offsetX, 0);
    }];
    
}
-(void)setupPageControl
{
    CGFloat pageY = CGRectGetMaxY(self.scrollView.frame)-20;
    self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake((self.view.frame.size.width-100)/2+20,pageY,40,20)];
    self.pageControl.numberOfPages = IMAGECOUNT;
    self.pageControl.enabled = NO;
    self.pageControl.currentPageIndicatorTintColor = [UIColor getColorWithHexNumber:@"5CC6AB"];
    self.pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
    [self.scroll insertSubview:self.pageControl aboveSubview:self.scrollView];
}

//-(void)scrollViewDidScroll:(UIScrollView *)scrollView
//{
//    CGPoint page = self.scrollView.contentOffset;
//    self.pageControl.currentPage = page.x /[UIScreen mainScreen].bounds.size.width + 0.5;
//}

-(void)onClickImage
{
    NSLog(@"点击图片%ld",(long)self.pageControl.currentPage);
    if (self.pageControl.currentPage == 0) {
        
        HJDBannerOneViewController *bannerOne = [[HJDBannerOneViewController alloc]init];
        HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:bannerOne];
        [self presentViewController:nav animated:YES completion:nil];
       
        
    }else if (self.pageControl.currentPage == 1){
        
       HJDBannerTwoViewController *bannerTwo = [[HJDBannerTwoViewController alloc]init];
        HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:bannerTwo];
        [self presentViewController:nav animated:YES completion:nil];
        
    }else if (self.pageControl.currentPage == 2){
        
        HJDBannerThreeViewController *bannerThree = [[HJDBannerThreeViewController alloc]init];
        HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:bannerThree];
        [self presentViewController:nav animated:YES completion:nil];
    
    }else if (self.pageControl.currentPage == 3){
        
        HJDBannerFourViewController *bannerFour = [[HJDBannerFourViewController alloc]init];
        HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:bannerFour];
        [self presentViewController:nav animated:YES completion:nil];
    
    }else{
        
        HJDBannerFiveViewController *bannerFive = [[HJDBannerFiveViewController alloc]init];
        HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:bannerFive];
        [self presentViewController:nav animated:YES completion:nil];
        
    }
}



-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    
    //将要拖拽是停止定时器
    [self.timer invalidate];
}
//结束拖拽调用
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    [self addTimer];
}

//时间准备表
-(void)papreBtnClick
{
    
    HJDDetailTimeTableViewController *detail = [[HJDDetailTimeTableViewController alloc]init];
    HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:detail];
    [self presentViewController:nav animated:YES completion:nil];

}

-(void)oneClick
{
    // 检测是否安装了QQ
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"mqq://"]]) {
        
        UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectZero];
        //貌似现在这个不能用了
        //    NSString * str = [NSString stringWithFormat:@"http://wpa.qq.com/msgrd?v=3&uin=%@&site=qq&menu=yes", @"742308143"];
        //记得plist文件里面要添加信任列表.
        NSString * string = @"mqq://im/chat?chat_type=wpa&uin=549952446&version=1&src_type=web";
        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:string]]];
        [self.view addSubview:webView];
        NSLog(@"你安装了qq");
        
    }else{
        [MBProgressHUD  showError:@"你没有安装QQ"];
        NSLog(@"没有安装");
    }

    NSLog(@"one");
}

-(void)twoClick
{
    HJDRegistrationViewController *registration = [[HJDRegistrationViewController alloc]init];
    HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:registration];
    [self presentViewController:nav animated:YES completion:nil];
//    [self.navigationController pushViewController:registration animated:YES];
}

-(void)threeClick
{
    HJDGestationViewController *gestation = [[HJDGestationViewController alloc]init];
    HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:gestation];
    [self presentViewController:nav animated:YES completion:nil];//    [self.navigationController pushViewController:gestation animated:YES];
}

-(void)fourClick
{
    HJDPofileControllerr *pofile = [[HJDPofileControllerr alloc]init];
    HJDNavigationController *nav = [[HJDNavigationController alloc]initWithRootViewController:pofile];
    [self presentViewController:nav animated:YES completion:nil];//    [self.navigationController pushViewController:pofile animated:YES];
}

-(void)resultClick
{
    NSLog(@"咨询");
}



-(void)upDayClick
{
    m -= 1;
    if (m<=0) {
        m = 0;
    }else
    self.timeLbl.text = [NSString stringWithFormat:@"%ld",(long)m];

    
    NSLog(@"上一天");
}

-(void)nextDayClick
{
    m += 1;
    self.timeLbl.text = [NSString stringWithFormat:@"%ld",(long)m];

    NSLog(@"下一天");
}


-(void)push
{
    
    HJDViewController *VC = [[HJDViewController alloc]init];
    [self.navigationController pushViewController:VC animated:YES];
    
}


//添加内容
-(void)setUpContent
{
    HJDMondayTableViewController *social = [[HJDMondayTableViewController alloc]init];
//    social.title = @"一";
    [self addChildViewController:social];
    HJDTuesdayTableViewController *social1 = [[HJDTuesdayTableViewController alloc] init];
//    social1.title = @"二";
    [self addChildViewController:social1];
    
    HJDWednesdayTableViewController *social2 = [[HJDWednesdayTableViewController alloc] init];
//    social2.title = @"三";
    [self addChildViewController:social2];
    
    HJDThursdayTableViewController *social3 = [[HJDThursdayTableViewController alloc] init];
//    social3.title/ = @"四";
    [self addChildViewController:social3];
    
    HJDFridayTableViewController *social4 = [[HJDFridayTableViewController alloc] init];
//    social4.title = @"五";
    [self addChildViewController:social4];
    
    HJDSaturdayTableViewController *social5 = [[HJDSaturdayTableViewController alloc] init];
//    social5.title = @"六";
    [self addChildViewController:social5];
    
    HJDSundayTableViewController *social6 = [[HJDSundayTableViewController alloc] init];
//    social6.title = @"日";
    [self addChildViewController:social6];
    
}


/**
 *   添加标题
 */
-(void)setUpTitle
{
    CGFloat lblW = (HJDWidth -45 -30)/7;
    CGFloat lblY = 0;
    CGFloat lblH = self.upScrollView.frame.size.height;
    NSArray * arrWeek=[NSArray arrayWithObjects:@"一",@"二",@"三",@"四",@"五",@"六",@"日", nil];
    for (NSInteger i =0; i< arrWeek.count; i++) {
        HJDLabel *label = [[HJDLabel alloc] init];
        //        label.text = [NSString stringWithFormat:@"%ld",i+1];
//        label.text = [self.childViewControllers[i] title];
        NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
        NSDateComponents *comp = [[NSDateComponents alloc]init];
        NSInteger flags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday |
        NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
        NSDate *nowDate = [NSDate date];
        //    calendar.locale = [[NSLocale alloc]initWithLocaleIdentifier:];
        comp = [calendar components:flags fromDate:nowDate];
        long int week = [comp weekday];
        if (week == 1) {
            week = 8;
        }
        NSInteger shi = week -2;
        label.text = arrWeek[i];
        label.textColor = [UIColor whiteColor];
//        HJDLog(@"shi  ------%ld",(long)shi);
        CGFloat labelX = i * lblW;
        label.frame = CGRectMake(labelX, lblY, lblW, lblH);
        //        点击手势监听
        [label addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelClick:)]];
        //        得到索引
        label.tag = i;
        [self.upScrollView addSubview:label];
        //        显示第一个label
        if (i == shi) { // 最前面的label
            label.scale = 1.0;
        }
        
    }
    
    // 设置contentSize
    self.upScrollView.contentSize = CGSizeMake(arrWeek.count * lblW, 0);
    self.downScrollView.contentSize = CGSizeMake((arrWeek.count * [UIScreen mainScreen].bounds.size.width)-130, 0);
}


//监听顶部label点击
-(void)labelClick:(UITapGestureRecognizer *)tap
{
    //    取出被点击label的索引
    NSInteger index = tap.view.tag;
    //    让底部的内容scrollView滚动到对应的位置
    CGPoint offset = self.downScrollView.contentOffset;
    //    X的偏移量
    offset.x = index * self.downScrollView.frame.size.width;
    [self.downScrollView setContentOffset:offset animated:YES];
    
    
}
/**
 * scrollView结束了滚动动画以后就会调用这个方法（比如- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;方法执行的动画完毕后）
 */

-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
    CGFloat width = scrollView.frame.size.width;
    CGFloat height = scrollView.frame.size.height;
    CGFloat offsetX = scrollView.contentOffset.x;

    //   当前位置需要显示的控制器的索引
    NSInteger index = offsetX / width;
//    HJDLog( @"diji------%ld",(long)index);
    //   取出需要显示的控制器
    UIViewController *willShowVC = self.childViewControllers[index];
    //    如果当前位置显示，就直接返回
    if ([willShowVC isViewLoaded]) return;
    // 添加控制器的view到contentScrollView中
    willShowVC.view.frame = CGRectMake(offsetX, 0, width, height);
    [self.downScrollView addSubview:willShowVC.view];
    
}

/**
 * 手指松开scrollView后，scrollView停止减速完毕就会调用这个
 */
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    [self scrollViewDidEndScrollingAnimation:scrollView];
    
}
/**
 *   只要scrollView在滚动，就会调用
 */


-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if ([scrollView isEqual:self.downScrollView]) {
    
        CGFloat scale = scrollView.contentOffset.x / scrollView.frame.size.width;
        if (scale < 0 || scale > 6) return;
        
        // 获得需要操作的左边label
        NSInteger leftIndex = scale;
        HJDLabel *leftLabel = self.upScrollView.subviews[leftIndex];
        
        // 获得需要操作的右边label
        NSInteger rightIndex = leftIndex + 1;
        HJDLabel *rightLabel = (rightIndex == 7) ? nil : self.upScrollView.subviews[rightIndex];
        
        // 右边比例
        CGFloat rightScale = scale - leftIndex;
        // 左边比例
        CGFloat leftScale = 1 - rightScale;
        
        // 设置label的比例
        leftLabel.scale = leftScale;
        rightLabel.scale = rightScale;

    }
    else if ([scrollView isEqual:self.scrollView]) {
        CGPoint page = self.scrollView.contentOffset;
        self.pageControl.currentPage = page.x /[UIScreen mainScreen].bounds.size.width + 0.5;
    }
    

    
    
   }




@end
